package com.hjm.project.accounts.virtualPolicyTemplate.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.accounts.virtualPolicyTemplate.domain.VirtualPolicyTemplate;
import com.hjm.project.accounts.virtualPolicyTemplate.service.IVirtualPolicyTemplateService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import javax.annotation.Resource;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 商户虚拟政策默认模板Controller
 * 
 * @author maker-platform
 * @date 2022-03-14
 */
@Controller
@RequestMapping("/accounts/virtualPolicyTemplate")
public class VirtualPolicyTemplateController extends BaseController {
    private String prefix = "accounts/virtualPolicyTemplate";

    @Resource
    private IVirtualPolicyTemplateService virtualPolicyTemplateService;

    @RequiresPermissions("accounts:virtualPolicyTemplate:view")
    @GetMapping()
    public String virtualPolicyTemplate() {
        return prefix + "/virtualPolicyTemplate";
    }

    /**
     * 查询商户虚拟政策默认模板列表
     */
    @RequiresPermissions("accounts:virtualPolicyTemplate:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VirtualPolicyTemplate virtualPolicyTemplate) {
        startPage();
        List<VirtualPolicyTemplate> list = virtualPolicyTemplateService.selectVirtualPolicyTemplateList(virtualPolicyTemplate);
        return getDataTable(list);
    }

    /**
     * 导出商户虚拟政策默认模板列表
     */
    @RequiresPermissions("accounts:virtualPolicyTemplate:export")
    @Log(title = "商户虚拟政策默认模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VirtualPolicyTemplate virtualPolicyTemplate) {
        List<VirtualPolicyTemplate> list = virtualPolicyTemplateService.selectVirtualPolicyTemplateList(virtualPolicyTemplate);
        ExcelUtil<VirtualPolicyTemplate> util = new ExcelUtil<VirtualPolicyTemplate>(VirtualPolicyTemplate.class);
        return util.exportExcel(list, "virtualPolicyTemplate");
    }

    /**
     * 新增商户虚拟政策默认模板
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商户虚拟政策默认模板
     */
    @RequiresPermissions("accounts:virtualPolicyTemplate:add")
    @Log(title = "商户虚拟政策默认模板", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VirtualPolicyTemplate virtualPolicyTemplate) {
        return toAjax(virtualPolicyTemplateService.insertVirtualPolicyTemplate(virtualPolicyTemplate));
    }

    /**
     * 修改商户虚拟政策默认模板
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        VirtualPolicyTemplate virtualPolicyTemplate = virtualPolicyTemplateService.selectVirtualPolicyTemplateById(id);
        mmap.put("virtualPolicyTemplate", virtualPolicyTemplate);
        return prefix + "/edit";
    }

    /**
     * 修改保存商户虚拟政策默认模板
     */
    @RequiresPermissions("accounts:virtualPolicyTemplate:edit")
    @Log(title = "商户虚拟政策默认模板", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VirtualPolicyTemplate virtualPolicyTemplate) {
        return toAjax(virtualPolicyTemplateService.updateVirtualPolicyTemplate(virtualPolicyTemplate));
    }

    /**
     * 删除商户虚拟政策默认模板
     */
    @RequiresPermissions("accounts:virtualPolicyTemplate:remove")
    @Log(title = "商户虚拟政策默认模板", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(virtualPolicyTemplateService.deleteVirtualPolicyTemplateByIds(ids));
    }
}
